#!/bin/bash
file=/data/shell-scripts/$1
if [ ! -d $file ]; then
   mkdir -p /data/shell-scripts/$1
fi

if [ ! -d $file/$2 ]; then
   mkdir -p /data/shell-scripts/$1/$2
fi


echo "---------------"
echo "k8s部署新应用"
cp -R /data/config/$1/Dockerfile-$2  Dockerfile-$2

tag=$2.`date '+%Y%m%d%H%M%S'`
if docker images|grep $2|grep ${env};then
    docker rmi -f `docker images | grep $1 |awk '{print $3}'`
fi

docker build  -t="swr.cn-east-3.myhuaweicloud.com/access/$1:${tag}" -f Dockerfile-$2 .
docker push swr.cn-east-3.myhuaweicloud.com/access/$1:${tag}

cd /data/shell-scripts/$1/$2
cp -r /data/sh/deployment.yaml-$2  deployment.yaml
sed -i "s/abmau-edi/$1/g" deployment.yaml
kubectl -n $3 apply -f deployment.yaml